package com.gec.servlet;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.gec.entity.Cart;
import com.gec.entity.CartItem;


@WebServlet("/UpdateBuyNumServlet")
public class UpdateBuyNumServlet extends HttpServlet	 {
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
	  	    throws ServletException, IOException {
	  	String pid = request.getParameter("pid");
	  	String s = request.getParameter("buyNum");
	  	int buyNum = Integer.parseInt(s);
	  	HttpSession session = request.getSession();
	  	Cart cart = (Cart) session.getAttribute("cart");
	  	Map<String, CartItem> cartItems = cart.getCartItems();
	  	cartItems.get(pid).setBuyNum(buyNum);
	  	response.sendRedirect("cart.jsp");
	      }

}
